	package com.jx.controller;

import java.io.IOException;
import java.io.PrintWriter;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import com.jx.dao.FindFuncsDao;
import com.jx.daoimpl.FindFuncsDaoImpl;
import com.jx.model.Admin;
import com.jx.model.Func;
import com.jx.service.AdminService;
import com.jx.servicrimpl.AdminServiceImpl;
/**
 * 登录界面的servlet
 * @author yu
 *
 */
public class LoginController extends HttpServlet{
	
       @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    	// TODO Auto-generated method stub
    	doPost(req, resp);
    }
        @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        	// TODO Auto-generated method stub
            
            AdminService adminservice = new AdminServiceImpl();
        	HttpSession session =  req.getSession();
        	String aname =  req.getParameter("aname");
        	String apsw =  req.getParameter("apsw");
        	PrintWriter pw =  resp.getWriter();
        	Admin admin = adminservice.validateUser(aname, apsw);
        	session.setAttribute("currentadmin", admin);
        	if(admin.getAname()!=null){
        		//session.setAttribute("currentadmin", admin);
        		pw.write("1");
        	}else{
        		pw.write("0");
        	}

        }
}
